package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Mapper
public interface TestMapper{


    //查询所有的试卷   把前端传递来的参数封装进testBean对象里
    List<TestBean> findAll(@Param("t") TestBean testBean);

    /**
     * 根据ID查询试卷
     * @param id
     * @return
     */
    @Results({
            @Result(id = true, property = "id", column = "id", javaType = Long.class),
            @Result(property = "testName", column = "test_name", javaType = String.class),
            @Result(property = "status", column = "status", javaType = Integer.class),
            @Result(property = "testType", column = "test_type", javaType = Integer.class),
    })
    @Select("select * from test_info where  id = #{id}")
    TestBean getOneById(Long id);


    /**
     * 新增试卷
     * @param testBean
     * @return 受影响的行数
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "t.id"
    )
    @Insert("insert into test_info " +
            "(test_name,test_type,ques_num,create_time,status,fk_section_id,fk_subject_id,fk_test_typeid)" +
            " values(#{t.testName},#{t.testType},#{t.quesNum},now(),'0',#{t.sectionBean.id},#{t.subjectBean.id},#{t.testTypeBean.id})")
    int addTestBean(@Param("t") TestBean testBean);

    /**
     * 修改试卷
     * @param testBean
     * @return
     */
    @Update("<script>" +
            "update test_info" +
            "<set>" +
            "<if test='t.testName != null'>" +
            " test_name = #{t.testName}," +
            "</if>" +
            "<if test='t.testType != null'>" +
            " fk_test_typeid = #{t.testType}," +
            "</if>" +
            "<if test='t.quesNum != null'>" +
            " ques_num = #{t.quesNum}," +
            "</if>" +
            "<if test='t.status != null'>" +
            " status = #{t.status}," +
            "</if>" +
            "</set>" +
            "where id = #{t.id}" +
            "</script>")
    int updateTestBean(@Param("t") TestBean testBean);

    /**
     * 删除试卷
     * @param id
     * @return 受影响的行数
     */
    @Delete("delete from test_info where id = #{id}")
    int deleteTestBean(@Param("id")Long id);





}